#include <stdio.h>
#include "templates.h"

void PrintFormBirthday(void)
{
    int i = 0;
    const char * monthArr[12] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
    printf("<tr>\n<td><label>Birthday: </label></td>\n<td>\n<div class=\"month_div beauty_select\"><select class=\"month\" name=\"month\">\n");
    printf("<option value=\"none\">Month:</option>\n");
    for (i = 0; i < 12; ++i)
    {
        printf("<option value=\"%s\">%s</option>\n", monthArr[i], monthArr[i]);
    }
    printf("</select>\n");
    printf("</div>\n");
    printf("<div class=\"day_div beauty_select\">\n");
    printf("<select class=\"day\" name=\"day\">\n");
    printf("<option value=\"none\">Day:</option>\n");
    for (i = 1; i <= 31; ++i)
    {
        printf("<option value=\"%d\">%d</option>\n", i, i);
    }
    printf("</select>\n");
    printf("</div>\n");
    printf("<div class=\"year_div beauty_select\">\n");
    printf("<select class=\"year\" name=\"year\">\n");
    printf("<option value=\"none\">Year:</option>\n", i);
    for (i = 2012; i >= 1905; --i)
    {
        printf("<option value=\"%d\">%d</option>\n", i, i);
    }
    printf("</select>");
    printf("</div>\n");
    printf("</td>\n</tr>\n");
}

void PrintForm(void)
{
    printf("<form action=\"/cgi-bin/form_handler.cgi\" method=\"post\" enctype=\"text/plain\">\n");
    printf("<table class=\"input_table\" summary=\"\">\n");
    printf("<tr>\n<td><label>First Name: </label></td>\n<td><div class=\"input_div\"><input type=\"text\" name=\"first_name\"></div></td>\n</tr>\n");
    printf("<tr>\n<td><label>Last Name: </label></td>\n<td><div class=\"input_div\"><input type=\"text\" name=\"last_name\"></div></td>\n</tr>\n");
    printf("<tr>\n<td><label>Your Email: </label></td>\n<td><div class=\"input_div\"><input type=\"text\" name=\"email\"></div></td>\n</tr>\n");
    printf("<tr>\n<td><label>Re-enter Email: </label></td>\n<td><div class=\"input_div\"><input type=\"text\" name=\"re_email\"></div></td>\n</tr>\n");
    printf("<tr>\n<td><label>New Password: </label></td>\n<td><div class=\"input_div\"><input type=\"password\" name=\"password\"></div></td>\n</tr>\n");
    printf("<tr>\n<td><label>I am: </label></td>\n<td>\n<div class=\"div_sex beauty_select\">\n<select class=\"select_sex\" name=\"sex\">\n");
    printf("<option value=\"none\">Select Sex:</option>\n");
    printf("<option value=\"male\">Male</option>\n");
    printf("<option value=\"female\">Female</option>\n");
    printf("</select>\n</div>\n</td>\n</tr>\n");
    PrintFormBirthday();
    
    printf("<tr>\n<td></td>\n<td><a href=\"https://www.facebook.com/\" class=\"why_link\">Why do I need to provide this?</a></td>\n</tr>\n");
    printf("<tr>\n<td></td>\n<td><input class=\"submit\" value=\"submit\" type=\"image\" src=\"/images/fb_form/submit.png\"></td>\n</tr>\n");
    printf("</table>\n");    
    printf("</form>\n");
}

void main(void)
{
    PrintHTTPResponseHeader();
    PrintHTMLHead("Form", "Sign Up", "It's free and always will be.");
    PrintForm();
    PrintHTMLEnd();
}